﻿<style type="text/css">
.plan-north-div1 {
	padding-top: 3px;
	padding-left: 2px;
	font-weight: 500;
	font-size: 12px;
	color: #596573;
	float:left;
}
.plan-north-div2 {
	padding-top: 3px;
	padding-right: 2px;
	float: right;
}
</style>
	<div class="easyui-layout" style="height:525px;width:948px;overflow:hidden;margin:0px auto">
		<div data-options="region:'north',split:false" style="height:36px;background:#dbeaf9;overflow:hidden;border-bottom:none;">
			<div>
				<div class="plan-north-div1">
					<a href="javascript:void(0);" onclick="beforeOrAfterDate('-');" class="easyui-linkbutton" data-options="iconCls:'icon-back-oval',plain:true"></a>
					&nbsp;<a href="javascript:void(0);" onclick="beforeOrAfterDate('+');" class="easyui-linkbutton" data-options="iconCls:'icon-next',plain:true"></a>
					&nbsp;<span id="sfe_vps_north_span">2012-11-25 ~ 2012-12-01</span>&nbsp;&nbsp;
					<input id="sfe_vps_north_combobox" name="employeeidname"  style="width:200px;"/>
				</div>
				<div class="plan-north-div2">
					<a class="easyui-linkbutton" onclick="vps_refresh();" data-options="iconCls:'icon-refresh',plain:true"></a>
				</div>
			</div>
		</div>
		<div data-options="region:'center'" style="padding:0">
		    <table id="sfe_vps_center_datagrid"></table>
		</div>
	</div>
<script type="text/javascript">
var vps_ovaldate = new Date();
var vps_ovaldateStr = formatCalendarDate(vps_ovaldate,'-');
var sfe_vps_center_datagrid;
$(function(){
	getUserComboTree();
});

    /**
	 * UserSearch调用job获取数据
	 * 根据用户进行搜索
	 */
var sfe_vps_north_combobox;

function getUserComboTree() {
	var variable = new Array('__methodName', '__token', 'pagename', 'actionname', '__params');
	var value = new Array('wsActionJSON', token, 'p_usersynctree', 'usersynctree', "{'currentdate':'"+vps_ovaldateStr+"'}");
	var dataStr = getJsonData(variable, value);
	connectionServlet(dataStr, getUserComboTreeReturn);
}

function getUserComboTreeReturn(data) {
	var rowsData;
	if (data.successflag == 'false') {
		return;
	}
	tempResult = data.result;
	if (typeof(tempResult) == 'undefined') {
		return;
	}
	if (typeof(tempResult.userdata) != 'undefined') {
		rowsData = tempResult.userdata;
	} else {
		rowsData = [];
	}
	sfe_vps_north_combobox = $('#sfe_vps_north_combobox').combobox({
			valueField : 'id',
			textField : 'text',
			onSelect : function (record) {
				getVisitplanShowDatagrid();
			}
		});
	sfe_vps_north_combobox.combobox('loadData', rowsData);
	getVisitplanShowDatagrid();
}

    /**
	 * 显示搜索人的计划（加载数据）
	 * 
	 */

function getVisitplanShowDatagrid(){
    var employeeid = sfe_vps_north_combobox.combobox('getValue');
	var variable = new Array('__methodName', '__token', 'pagename', 'actionname', '__params');
	var value = new Array('wsActionJSON', token, 'p_visitplanshow', 'visitplanshow', "{'currentdate':'"+vps_ovaldateStr+"','employeeid':" + employeeid + "}");
	var dataStr = getJsonData(variable, value);
	connectionServlet(dataStr, getVisitplanShowDatagridReturn);
}

function getVisitplanShowDatagridReturn(data){
	var rowsData;
		if(data.successflag == 'false'){
		     return ;
		}
		tempResult = data.result;
		
        if(typeof (tempResult.dates) != 'undefined'){
		     $('#sfe_vps_north_span').html(tempResult.dates.weekrange);
		}	
        if(typeof (tempResult) == 'undefined'){
		     return ;
		}		
		if(typeof (tempResult.alldata) != 'undefined'){
		   rowsData = tempResult.alldata;
		}else{
		    rowsData = [];
		}
	    sfe_vps_center_datagrid = $('#sfe_vps_center_datagrid').datagrid({
		rownumbers:true,
		border:false,
		height:525,
		fit:true,
		nowrap:false,
		fitColumns:true,
		columns:[[
		    {field:'orgcode',title:'机构代码',width:100,sortable:true},
			{field:'orgname',title:'机构名称',width:200,sortable:true},
			{field:'visitstatus',title:'拜访状态',width:100,align:'right',sortable:true,formatter: function(value,row,index){
			        if(value != null){
					    if(value == 1){
						    return '拜访';
						}else{
						     return '其他';
						}
					}
			   }
            },
			{field:'planvisitdate',title:'拜访时间',width:100,align:'right',sortable:true}
			]],
		groupField:'planvisitdate',
		view: groupview,
		groupFormatter:function(value, rows){
			var dateStr = value.split('-');
			var changeDate = new Date(dateStr[0], dateStr[1]-1,dateStr[2]);
			return value +"("+getWeek(changeDate)+")";
		}
	});
	sfe_vps_center_datagrid.datagrid('loadData',rowsData);
}


    /**
	 * 点击左右箭头显示前一个月后一个月
	 * 
	 */
function beforeOrAfterDate(sign) {
    var getweekdate = beforeOrAfterWeek(vps_ovaldate,sign).split(",")[0];
	var splitStr = getweekdate.split('-');
	vps_ovaldate = new Date(splitStr[0],splitStr[1]-1,splitStr[2]);
	vps_ovaldateStr = formatCalendarDate(vps_ovaldate,'-');
	getVisitplanShowDatagrid();
		
}

   /**
	 * 刷新
	 * 
	 */
function vps_refresh(){
     getVisitplanShowDatagrid();
}


</script>
